import { message } from '@/utils/util';

export default {
  name: 'audit-price-list-table',
  props: {
    data: {
      type: Array,
      default: () => [],
    },
    total: {
      type: Number,
      default: 0,
    },
    pageNum: {
      type: Number,
      default: 1,
    },
    pageSize: {
      type: Number,
      default: 10,
    },
    loading: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    currentPage() {
      return this.pageNum;
    },
    currentPageSize() {
      return this.pageSize;
    },
  },
  data() {
    return {};
  },
  methods: {
    onPageSizeChange(pageSize) {
      this.$emit('pageSizeChange', pageSize);
    },
    onPageNumChange(pageNum) {
      this.$emit('pageNumChange', pageNum);
    },
    onOpenDetailModal(row) {
      this.$emit('onOpenEditModal', { taskIds: [row.id] });
    },
    async onBatchingAuditGoods() {
      try {
        let selectdRow = this.$refs.storeTable.selection.length === 0 ? null : this.$refs.storeTable.selection;
        if (!selectdRow) {
          message('提示', '请选择商品记录', 'warning');
          return;
        }
        if (selectdRow.length > 50) {
          message('提示', '最多选择50条数据', 'warning');
          return;
        }
        console.log('selectdRow', selectdRow);
        let taskIds = [];
        selectdRow.map(item => {
          taskIds.push(item.id);
        });
        this.$emit('onOpenEditModal', { taskIds });
      } catch (e) {
        message('错误', e.message, 'error');
      }
    },
    // 一键审核
    async onKeyAuditGoods() {
      let selectdRow = this.$refs.storeTable.selection.length === 0 ? null : this.$refs.storeTable.selection;
      if (!selectdRow) {
        message('提示', '请选择商品记录', 'warning');
        return;
      }
      const manualList = selectdRow.filter(item => item.handleType === 'PASSIVE');
      if (manualList.length > 0) {
        message('提示', '当前含有手动审核数据，只能操作自动审核的数据~', 'warning');
        return;
      }
      if (selectdRow.length > 50) {
        message('提示', '最多选择50条数据', 'warning');
        return;
      }
      console.log('selectdRow', selectdRow);
      let taskIds = [];
      selectdRow.map(item => {
        taskIds.push(item.id);
      });
      this.$emit('onKeyAuditGoods', { taskIds });
    },
  },
  mounted() {},
};
